/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import BD.MySql;
import Clases.Responsable;
import java.util.List;

/**
 *
 * @author angelo
 */
public class DAOResponsable {

    public static boolean modificarResponsable(Responsable responsable) {
        String sql = "UPDATE Responsable SET Nombre = ?, Apodo = ?, Email = ?, "
                + "PathFoto = ? WHERE Id_Responsable = ?";
        Object[] parametros = {responsable.getNombre(), responsable.getApodo(),
            responsable.getEmail(), responsable.getPathFoto(), responsable.getId_Responsable()};
        MySql mySql = new MySql();
        if (mySql.executeUpdate(sql, parametros) == 0) {
            return false;
        } else {
            return true;
        }
    }

    public static boolean cargarResponsable(Responsable responsable) {
        String sql = "INSERT INTO Responsable(Nombre, Apodo, Email, PathFoto) VALUES (?,?,?,?)";
        Object[] paramtros = {responsable.getNombre(), responsable.getApodo(), responsable.getEmail(), responsable.getPathFoto()};
        MySql mySql = new MySql();
        if (mySql.executeUpdate(sql, paramtros) == 0) {
            return false;
        } else {
            return true;
        }
    }

    public static boolean eliminarResponsable(Responsable responsable) {
        String sql = "DELETE FROM Responsable WHERE Id_Responsable = ?";
        Object[] parametros = {responsable.getId_Responsable()};
        MySql mySql = new MySql();
        if (mySql.executeUpdate(sql, parametros) == 0) {
            return false;
        } else {
            return true;
        }
    }

    public static List<Responsable> getResponsable() {
        String sql = "SELECT * FROM Responsable";
        MySql<Responsable> mySql = new MySql<Responsable>();
        List<Responsable> lista = mySql.executeQuery(sql, Responsable.class, null);
        return lista;
    }

    public static boolean emailDisponible(Responsable respo) {
        String sql = "SELECT * FROM Responsable where Email =  ?";
        Object[] parametros = {respo.getEmail()};
        MySql<Responsable> mySql = new MySql<Responsable>();
        List<Responsable> lista = mySql.executeQuery(sql, Responsable.class, parametros);
        if (lista.isEmpty()) {
            return true;
        } else {
            if (lista.get(0).getId_Responsable() == respo.getId_Responsable()) {
                return true;
            }
            return false;
        }
    }   

    public static Responsable getResponsableById(int id) {
        String sql = "select * from Responsable where Id_Responsable = ?";
        Object[] parametros = {id};
        MySql<Responsable> mySql = new MySql<Responsable>();
        List<Responsable> lista = mySql.executeQuery(sql, Responsable.class, parametros);
        return lista.get(0);
    }

    public static int getIdResponsableByEmail(String email) {
        String sql = "select * from Responsable where Email = ?";
        Object[] parametros = {email};
        MySql<Responsable> mySql = new MySql<Responsable>();
        List<Responsable> lista = mySql.executeQuery(sql, Responsable.class, parametros);
        return lista.get(0).getId_Responsable();
    }

    public static Responsable getResponsableByEmail(String email) {
        String sql = "select * from Responsable where Email = ?";
        Object[] parametros = {email};
        MySql<Responsable> mySql = new MySql<Responsable>();
        List<Responsable> lista = mySql.executeQuery(sql, Responsable.class, parametros);
        return lista.get(0);
    }
}
